package meituan;

import java.util.Scanner;

/**
 * @author le
 */
public class Meituan01
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);

        String origin  = in.nextLine();
        String tar = in.nextLine();

        // abcdefghijklmnopqrstuvwxyz  0 1 2 ... 25
        // meituan  // tu
        char[] a = origin.toCharArray();
        char[] b = tar.toCharArray();
        int slow = 0;
        int fast = 0;
        int count  = 0;
        int extra = 0;
        while(slow < b.length){
            if (fast == a.length){
                fast = 0;
                count++;
            }
            if (b[slow] == a[fast]){
                slow++;
            }

            fast++;

        }

        /*while(slow < b.length){

            while(fast < a.length){
                if (b[slow] == a[fast]){
                    slow++;
                }
                count += slow;
                fast++;
            }

        }*/
        System.out.println(count*a.length-b.length+fast);
        in.close();

    }
}
